Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat empty runtime namespaces as All Namespaces mode #658

Merged
merged 1 commit into from
Aug 11, 2023

Conversation

Jamstah
Copy link
Contributor

@Jamstah Jamstah commented Jul 14, 2023

This makes the empty string in the namespaces configuration watch all namespaces, as per the documented behaviour: https://github.com/quarkiverse/quarkus-operator-sdk/blob/main/core/runtime/src/main/java/io/quarkiverse/operatorsdk/runtime/RunTimeOperatorConfiguration.java#L56

Fixes #656

@Jamstah
Copy link
Contributor Author

Jamstah commented Jul 14, 2023

/cc @metacosm

@metacosm
Copy link
Member

Looks reasonable, was thinking about doing something similar indeed.

Would you mind changing the commit message so that it fits the conventional format, though, please?

@Jamstah Jamstah force-pushed the all-namespaces-mode branch 2 times, most recently from 3279685 to 7878952 Compare July 18, 2023 13:34
@Jamstah
Copy link
Contributor Author

Jamstah commented Jul 18, 2023

Like this? Happy to.

Hope you're enjoying your vacation.

Copy link
Contributor

@csviri csviri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@metacosm metacosm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we can't support this in a simpler way, a test case would help figure this out… Otherwise the general idea is the right one, I think.

// We use a default here so that we are able to detect if the configuration value is set to "". Setting the value to "" will
// reset the configuration and result in an empty Optional, but not setting the value at all will result in the default being
// applied.
@ConfigItem(defaultValue = QOSDK_USE_BUILDTIME_NAMESPACES)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it might not just be enough to set the default value to io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_ALL_NAMESPACES here. Ideally, we'd need a test to cover this, actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we set the default to WATCH_ALL_NAMESPACES we couldn't tell if there was no specific runtime setting, which means we would always override the build time property.

Maybe the build time property doesn't matter because it's only really intended to affect the manifests and not the runtime behaviour... but at the moment the code will honour the build time property if the runtime property is not set at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the build time property doesn't matter because it's only really intended to affect the manifests and not the runtime behaviour... but at the moment the code will honour the build time property if the runtime property is not set at all.

I would say that this is the intended behavior but I'm open to change my mind about this depending on what people think. The previous version used the same property for both build and runtimes, which was conducive to confusing which version was used ultimately. With the new generate-with-watched-namespaces property, it is now more explicit that the build time value is used mostly for generation purposes. Its value can indeed be propagated at runtime and it's indeed how things are currently implemented, just not sure if it actually make sense since it would make it more difficult to know exactly which configuration is used at runtime. Completely separating both might make more sense with that respect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my thinking with a property that was explicitly namespaced with manifests in the name to separate it from properties that affect the built image.

I feel like the manifests are really runtime configuration and tbh, I think using quarkus.operator-sdk.namespaces at build time should affect the manifests and not the image, and that would make conceptual sense. It breaks the duplicated properties rule though.

If the runtime configuration specifies an empty string as the namespaces to watch, we should treat that as all namespaces mode, mainly because that's how OLM signifies that an operator should watch all namespaces.

An empty string is treated the same as unset by the configuration parser, so we need to set a default on the field so we can explicitly check for it being unset, to determine if the empty string was used.

Fixes quarkiverse#656

Signed-off-by: James Hewitt <james.hewitt@uk.ibm.com>
@Jamstah Jamstah force-pushed the all-namespaces-mode branch from 7878952 to 310ee91 Compare July 19, 2023 08:59
@Jamstah
Copy link
Contributor Author

Jamstah commented Jul 19, 2023

I had a look at how to test this - at the moment the integration tests run a single operator with all the test controllers injected. If I were to set the global operator namespace property for those tests, it would break all the existing tests.

What are your thoughts on how to architect a test here? A second set of integration tests? A second profile? Something else?

@metacosm
Copy link
Member

metacosm commented Aug 9, 2023

I had a look at how to test this - at the moment the integration tests run a single operator with all the test controllers injected. If I were to set the global operator namespace property for those tests, it would break all the existing tests.

What are your thoughts on how to architect a test here? A second set of integration tests? A second profile? Something else?

I'm thinking about specific tests using a specific test profile.

@metacosm metacosm merged commit ad898c3 into quarkiverse:main Aug 11, 2023
@metacosm
Copy link
Member

Thank you. I will add tests in a separate PR.

@Jamstah
Copy link
Contributor Author

Jamstah commented Aug 11, 2023

Thanks Chris :)

I did have a look at it, but think I'd need more time for the profiles thing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Operators do not work with OLM all namespaces mode
3 participants